home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.src.lzh / libc / stdfdopen.c < prev    next >
C/C++ Source or Header  |  1980-01-01  |  842b  |  39 lines

  1. /*
  2.  * stdfdopen - ensure that the standard i/o descriptors are open,
  3.  *    to avoid mayhem.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include <sys/types.h>
  9.  
  10. #ifndef AMIGA
  11. # include <sys/stat.h>
  12. #endif /* !AMIGA */
  13.  
  14. #ifndef NSYSFILE
  15. # define NSYSFILE 3                    /* hmm, not on V8 */
  16. #endif
  17.  
  18. extern int errno;
  19.  
  20. void
  21. stdfdopen()            /* ensure standard descriptors are open */
  22. {
  23.     /*
  24.      *    As far as I know, the best the Amiga could do is
  25.      *    use iomode() to try to change the mode of the 'level 1'
  26.      *    file handle (descriptor) and see if an error was
  27.      *    returned!  ... forget it for now -- assume it's okay.
  28.      */
  29. #ifndef AMIGA
  30.     register int fd;
  31.     struct stat stbuf;
  32.  
  33.     for (fd = 0; fd < NSYSFILE; fd++)
  34.         if (fstat(fd, &stbuf) < 0 && errno == EBADF)
  35.             if (open("/dev/null", 2) != fd)    /* open read/write */
  36.                 exit(1);        /* bad news */
  37. #endif /* AMIGA */
  38. }
  39.